package com.zju.DoctorGo.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import java.util.Random;
@Component
public class EmailVerifyUtils {

    @Autowired
    private JavaMailSender mailSender;

    public void sendEmail(String targetEmailBox,String code){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("17857953119@163.com");	//设置邮件发送者
        message.setTo(targetEmailBox);		//设置邮件接收者
        message.setSubject("[软件工程]验证码");	//设置邮件主题
        message.setText("您的验证码为："+code+"，有效期为5分钟，请尽快验证。");		//设置邮件内容
        mailSender.send(message);
    }

    public String generateCode(int n){
        Random r = new Random();
        StringBuffer sb =new StringBuffer();
        for(int i = 0;i < n;i ++){
            int ran1 = r.nextInt(10);
            sb.append(String.valueOf(ran1));
        }
        return sb.toString();
    }


}
